﻿using CHS.ChengDu.Dtos;
using CHS.ChengDu.Service;
using CHS.ChengDu.Service.Interface.LIS;

using System.Web;
using System.Web.Http;


namespace Com.WebApiServe.Controllers
{

    [RoutePrefix("Api/CHS")]
    public class CHSController : ApiController
    {
        HttpContext _context;

        /// <summary>
        /// 犹黎    511321199312080346    22112630199
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("PrintLis")]
        [HttpPost]
        public HttpResult PrintLis(string id)
        {
            string data = "";
            try
            {
                data =  new Report().Print(id);
            }
            catch (System.Exception e)
            {
                return new HttpResult { Code = -1, Message = e.Message };
            }

            return new HttpResult { Data = data };
        }

        /// <summary>
        /// 接口初始化
        /// </summary>
        /// <returns></returns>
        [Route("Init")]
        [HttpPost]
        public  CHSInitDto Init()
        {
            CHSChengDu _chs = new CHSChengDu();
            int aint_appcode = -1;
            string astr_appmsg = "";
            _chs.CHS_Init(ref aint_appcode, ref astr_appmsg);
            CHSInitDto _output = new CHSInitDto() { aint_appcode = aint_appcode, astr_appmsg = astr_appmsg };
            return _output;
        }

        
        
        /// <summary>
        /// 安全控件调用-读卡
        /// </summary>
        /// <param name="_input"></param>
        /// <returns></returns>
        [Route("Call")]
        [HttpPost]
        public CHSCallOutputDto Call(CHSCallInputDto _input)
        {
            CHSChengDu _chs = new CHSChengDu();
            string _output = "";
            _chs.CHS_Call(_input.infno.ToString(), _input.input.ToString(), ref _output);
            CHSCallOutputDto _outputDto = new CHSCallOutputDto() { output = _output };
            return _outputDto;
        }
        /// <summary>
        /// 安全控件调用-打印
        /// </summary>
        /// <param name="_input"></param>
        /// <returns></returns>
        [Route("Print")]
        [HttpPost]
        public CHSCallOutputDto Print(CHSCallInputDto _input)
        {
            CHSChengDu _chs = new CHSChengDu();
            string _output = "";
            _chs.CHS_Pint(_input.input.ToString(), ref _output);
            CHSCallOutputDto _outputDto = new CHSCallOutputDto() { output = _output };
            return _outputDto;
        }
        /// <summary>
        /// 释放接口
        /// </summary>
        [Route("Destory")]
        [HttpPost]
        public CHSCallOutputDto Destory()
        {
            CHSChengDu _chs = new CHSChengDu();
            _chs.CHS_Destroy();
            CHSCallOutputDto _outputDto = new CHSCallOutputDto() { output = new {code = 0,message = "释放" } };
            return _outputDto;
        }
        #region 加密
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="_input"></param>
        /// <returns></returns>
        [Route("Encrypt")]
        [HttpPost]
        public CHSEncryptionOutput Encrypt(CHSEncryptionInput _input)
        {
            return CHSEncryption.gm_ecb_encrypt_key(_input);
        }
        #endregion

        #region 解密
        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="_input"></param>
        /// <returns></returns>
        [Route("Decrypt")]
        [HttpPost]
        public CHSEncryptionOutput Decrypt(CHSEncryptionInput _input)
        {
            return CHSEncryption.gm_ecb_decrypt_key(_input);
        }
        #endregion

        #region 签名
        /// <summary>
        /// 签名
        /// </summary>
        /// <param name="_input"></param>
        /// <returns></returns>
        [Route("SignIn")]
        [HttpPost]
        public CHSEncryptionOutput SignIn(CHSEncryptionInput _input)
        {
            return CHSEncryption.gm_sign_key(_input);
        }
        #endregion





    }
}
